<?php include("global-includes/breadcrumbs.php"); ?>
<?php
	$pictureCount = count($page["images"]);
	$comments = get_comments($page["id"], "product");
	$questions = get_questions($page["id"]);
	$commentCount = count($comments);
	$questionCount = count($questions);
?>
<div class="col-md-9">
	<div class="row">
		<?php if($pictureCount > 0): ?>
			<div class="col-md-4 productImages">
				<?php include("html-includes/product/items/gallery.php"); ?>
			</div>
		<?php endif; ?>
		<div class="col-md-<?php echo ($pictureCount > 0 ? "8" : "12")?> productDetails">
			<div class="row">
				<h1><?php echo $page["name"]; ?></h1>
				<?php echo translate("subcategory"); ?>: 
				<?php
					if(isset($page["category"]))
					{
						$bestCat = $page["category"];
					}
					elseif(isset($page["parent_category"]))
					{
						$bestCat = $page["parent_category"];
					}
					else
					{
						$bestCat = $page["super_category"];
					}
					
					echo $bestCat["name"];
				?>
				
				<div class="row rating">
					<div class="col-md-2"><?php echo translate("rating"); ?></div>
					<div class="col-md-10">
						<?php for($i = 1; $i <= 5; $i++):?>
							<a title="" class="<?php echo ($page["rating"] >= $i ? "selected" : ""); ?>"></a>
						<?php endfor;?>
					</div>
				</div>
				<div class="row priceRow">
					<div class="col-md-2"><?php echo translate("pret_unitar"); ?></div>
					<div class="col-md-10">
						<div class="row">
							<div class="col-md-7 productPrice">
								<?php echo $page["price"];?>
								<sup>/<?php echo strtolower(($page["quantity_type"] == 1 ? translate("set") : translate("piece"))); ?></sup>
							</div>
							<div class="col-md-5 discount">
								<?php if(isset($page["discount"]) && $page["discount"]["discount_percent"] > 0 || $page["discount"]["discount_static"] > 0): ?>
						
									<?php
										if($page["discount"]["discount_percent"] > 0)
										{
											echo "-".$page["discount"]["discount_percent"]."%";
										}
										elseif($page["discount"]["discount_static"] > 0)
										{
											echo "-".$page["discount"]["discount_static"]."".$settings["currency"];
										}
									?>
								
								<sup><?php echo translate("discount"); ?></sup>
								<?php endif; ?>
							</div>
							
							<div class="clearfix"></div>
							
							<?php 
								if($page["minimal_order"] > 1)
								{
									echo translate("comanda_mimima") . ": ".$page["minimal_order"].($page["quantity_type"] == 1 ? translate("sets") : translate("pieces"));
								} 
							?>
						</div>
					</div>
				</div>
				<div class="row stocksRow">
					<div class="col-md-2">
						<?php echo translate("preturi_engros"); ?>
					</div>
					<div class="col-md-10">
						<?php
							getWholesaleTable($page);
						?>
					</div>
				</div>
				
				<div class="row colorsRow">
					<div class="col-md-2">
						<?php echo translate("colors"); ?>
					</div>
					<div class="col-md-10">
						<?php foreach($page["properties"] as $property):?>
							<?php if($property["type"] == 2):?>
								<?php foreach($property["values"] as $propertyValue): ?>
									<a href="#" stock_id="<?php echo $propertyValue["stock_id"]; ?>" title="">
										<img src="<?php echo scripts_url().$propertyValue["thumb_name"]; ?>" alt="" />
									</a>
								<?php endforeach; ?>
							<?php endif;?>
						<?php endforeach;?>
						
					</div>
				</div>
				
				<div class="row viewsRow">
					<div class="col-md-2">
						<?php echo translate("product_views"); ?>
					</div>
					<div class="col-md-3">
						<?php
							$views = $connection->num_rows("SELECT * FROM product_views WHERE product_id = {$page["id"]}");
						?>
						<?php echo ($views ? $views : "0"); ?>
					</div>
					<div class="col-md-2">
						<?php echo translate("istorie_tranzactii"); ?>
					</div>
					<div class="col-md-5">
						<?php
							$orders = $connection->fetch_one("SELECT SUM(quantity) AS total_quantity, COUNT(id) AS total_transactions FROM order_items WHERE product_id = ?", array($page["id"]));
							
							if(!$orders || $orders["total_transactions"] == 0)
							{
								echo "0"; // FARA TRANZACTII
							}
							else
							{
								echo $orders["total_transactions"] . " " . translate("tranzactions") . " (" . $orders["total_quantity"] . " " . ($page["quantity_type"] == 1 ? translate("sets") : translate("pieces")) .")";
							}
						?><br />
						
						<a href="#feedback" data-toggle="tab"><?php echo translate("vezi_feedback");?></a>
						
					</div>
					<div class="clearfix"></div>
				</div>
				
			</div>
		</div>
		<div class="clearfix"></div>
		<ul class="nav nav-tabs">
		  <li class="active">
  			<a href="#product_details" data-toggle="tab"><?php echo translate("product_details"); ?></a>
		  </li>
		  <li><a href="#company_details" data-toggle="tab"><?php echo translate("company_details"); ?></a></li>
		  <li><a href="#feedback" data-toggle="tab"><?php echo translate("feedback"); ?></a></li>
		  <li class="pull-right"><a class="report" href="#"><?php echo translate("raporteaza_produs")?></a></li>
		</ul>
		
		<!-- Tab panes -->
		<div class="tab-content">
		  <div class="tab-pane active" id="product_details">
		  	<h3><?php echo translate("technical_details"); ?></h3>
		  	<ul>
		  		<?php foreach($page["properties"] as $property): ?>
		  			<?php if($property["type"] != 2):?>
		  				<li>
		  					<span><?php echo ucfirst($property["name"]); ?>:</span>
		  					<?php foreach($property["values"] as $propValue):?>
		  						<?php if($page["stock_id"] == $propValue["stock_id"]):?>
		  							<?php echo $propValue["name"]; ?>
		  						<?php endif; ?>
		  					<?php endforeach; ?>
		  					
		  				</li>
		  			<?php endif; ?>
		  		<?php endforeach;?>
		  	</ul>
		  	
		  	<h3><?php echo translate("ambalare_si_livrare"); ?></h3>
		  	
		  	<ul>
		  		<li>
		  			<span><?php echo translate("ambalare"); ?>:</span> 
		  			<?php 
			  			if($page["packaging"] == 1)
			  			{
			  				echo translate("cutie_de_carton");
			  			}
		  			?>
		  		</li><br />
		  		<li><span><?php echo translate("livrare"); ?>:</span> <?php echo $page["delivery_time"]. " " . translate("days"); ?></li>
		  	</ul>
		  	
		  	<h3><?php echo translate("specificatii"); ?></h3>
		  	
		  	<?php echo $page["description"]; ?>
		  	
		  </div>
		  <div class="tab-pane" id="company_details">
		  	<?php
		  		$company = $page["company"];
				
				$city = $connection->fetch_row("cities", $company["city_id"]);
				$county = $connection->fetch_row("counties", $company["county_id"]);
				
		  	?>
		  	<h3><?php echo $company["name"]; ?></h3>
		  	<ul>
		  		<?php if($city): ?>
			  		<li>
			  			<span><?php echo translate("city"); ?>:</span> <?php echo $city["name"]; ?>
		  			</li>
	  			<?php endif; ?>
	  			
	  			<?php if($county): ?>
			  		<li>
			  			<span><?php echo translate("county"); ?>:</span> <?php echo $county["name"]; ?>
		  			</li>
	  			<?php endif; ?>
		  		<li>
		  			<span><?php echo translate("business_type"); ?>:</span>
		  			<?php
		  				if($company["business_type"] == 1)
						{
							$businessType = translate("producator");
						}
						elseif($company["business_type"] == 2)
						{
							$businessType = translate("distribuitor");
						}
						elseif($company["business_type"] == 3)
						{
							$businessType = translate("furnizor");
						}
						
						echo ucfirst($businessType);
		  			?>
		  			 
	  			</li>
		  	</ul>
		  	
		  	<h3><?php echo translate("description"); ?></h3>
		  	<?php echo $company["description"]; ?>
		  	
		  </div>
		  <div class="tab-pane" id="feedback">
		  	<?php
		  		$comments = get_comments($page["id"], "product");
				
				include("html-includes/common/comments.php");
		  	?>
		  </div>
		</div>
		
		<div class="panel panel-default contactPanel">
		  <div class="panel-heading"><?php echo translate("trimite_mesaj_catre_furnizorul") ." ". $company["name"]; ?></div>
		   
		  <div class="panel-body">
		  		<?php if($client): ?>
	  				<div class="row">
				  		<form class="form-horizontal" role="form" id="companyContactForm">
					    	<div class=" col-md-7">
				    			<input type="hidden" name="company_id" value="<?php echo $company["id"]; ?>" />
				    			<input type="hidden" name="client_id" value="<?php echo $client["id"]; ?>" />
				    			<input type="hidden" name="product_id" value="<?php echo $page["id"]; ?>" />
			    			 	<div class="form-group">
						    		<label class="col-sm-2 control-label"><?php echo ucfirst("de_la"); ?></label>
									<div class="col-sm-6">
										<span class="form-control"><?php echo $client["name"]; ?></span>
							    	</div>
							  	</div>
							  	<div class="form-group">
					  				<label class="col-sm-2 control-label"><?php echo ucfirst("catre"); ?></label>
					  				<div class="col-sm-3">
					  					<img src="<?php echo site_url().$company["logo"]; ?>" class="img-responsive" alt="" />
					  				</div>
					  				<div class="col-sm-7">
					  					<a href="<?php echo $site_pages["companies"]["url"] . $company["url"]; ?>.html" title="<?php echo $company["name"]; ?>"><?php echo $company["name"]; ?></a>
					  				</div>
							  	</div>
					    		
					    	</div>
					    	<div class="col-md-5">
					    		<label for="contactMessage" class="col-sm-4 text-left"><?php echo ucfirst(translate("message")); ?></label>
							  	<textarea class="form-control col-sm-7" id="contactMessage" name="message" placeholder="<?php echo ucfirst(translate("message")); ?>"></textarea>
							  	
							  	<button class="btn btn-success pull-right" id="sendCompanyMessage"><?php echo strtolower(translate("send")); ?></button>
					    	</div>
					    	
					    	
				    	</form>
			    	</div>
		    	<?php else: ?>
		    		<a class="btn btn-default" id="loginButton" href="<?php echo $site_pages["login"]["url"]; ?>"><?php echo translate("login"); ?></a>
		    	<?php endif;?>
		   	
		    <div class="clearfix"></div>
		  </div>
		</div>
		
		
	</div>
	
	
</div>

<?php include("html-includes/product/items/sidebar.php"); ?>

<div class="clearfix"></div>
</div>